package com.source.baseData.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.source.baseData.entity.PoultryCategory;
import com.source.baseData.vo.PoultryCategoryVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author fengq
 * @since 2021-02-06
 */
@Repository
public interface PoultryCategoryMapper extends BaseMapper<PoultryCategory> {

    /**
     * getListVo 查询所有的PoultryCategoryVo
     * @param  page
     * @return 返回封装List<PoultryCategoryVo>
     */
    @Select("select b.poultryCategoryId,poultryCategoryNumber,poultryCategoryName,detail,d.poultryParentName,c.`name`,a.slaughterHouseName,b.slaughterHouseId,b.parentId \n" +
            "from slaughter_house as a,poultry_category as b,sys_user as c,poultry_category_parent as d\n" +
            "where a.slaughterHouseId=b.slaughterHouseId\n" +
            "and a.isDelete=0 " +
            "and b.isDelete=0 " +
            "and c.isDelete=0 " +
            "and d.isDelete=0 " +
            "and a.userId=c.userId\n" +
            "and b.parentId=d.poultryCategoryParentId")
    IPage<PoultryCategoryVo> getPageVo(Page<PoultryCategoryVo> page);

    /**
     * getOneById 根据poultryCategoryId查询记录，
     * @param poultryCategoryId
     * @return 返回封装类PoultryCategoryVo
     */
    @Select("select b.poultryCategoryId,poultryCategoryNumber,poultryCategoryName,detail,d.poultryParentName,c.`name`,a.slaughterHouseName,b.slaughterHouseId,b.parentId \n" +
            "from slaughter_house as a,poultry_category as b,sys_user as c,poultry_category_parent as d\n" +
            "where a.slaughterHouseId=b.slaughterHouseId\n" +
            "and a.isDelete=0 " +
            "and b.isDelete=0 " +
            "and c.isDelete=0 " +
            "and d.isDelete=0 " +
            "and a.userId=c.userId\n" +
            "and b.parentId=d.poultryCategoryParentId " +
            "and b.poultryCategoryId=${poultryCategoryId}")
    PoultryCategoryVo getOneById(@Param("poultryCategoryId") String poultryCategoryId);

    /**
     * getVoByLike 多字段模糊查询
     * @param keyword
     * @param page
     * @return
     */
    @Select("select b.poultryCategoryId,poultryCategoryNumber,poultryCategoryName,detail,d.poultryParentName,c.`name`,a.slaughterHouseName,b.slaughterHouseId,b.parentId \n" +
            "from slaughter_house as a,poultry_category as b,sys_user as c,poultry_category_parent as d\n" +
            "where a.slaughterHouseId=b.slaughterHouseId\n" +
            "and a.isDelete=0 \n" +
            "and b.isDelete=0 \n" +
            "and c.isDelete=0 \n" +
            "and d.isDelete=0 \n" +
            "and a.userId=c.userId\n" +
            "and b.parentId=d.poultryCategoryParentId \n" +
            "and concat_ws(',',poultryCategoryNumber,poultryCategoryName,d.poultryParentName,a.slaughterHouseName, detail) like '%${keyword}%'")
    IPage<PoultryCategoryVo> getVoByLike(@Param("keyword")String keyword,Page<PoultryCategoryVo> page);

}
